using System;
using System.Collections.Generic;
using System.Linq;

using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.Dialog;

namespace Socialite
{
	[MonoTouch.Foundation.Register("WhatsHotScreen")]
	public partial class WhatsHotScreen : DialogViewController, IMultiViewScreen
	{
		List<Place> _places;
		List<Place> _favoritePlaces;
		WhatsHotViewModeSelectorElement _selectorElement;
		
		public WhatsHotScreen () : base (UITableViewStyle.Grouped, null)
		{
			Root = new RootElement ("What's Hot");
			Root.UnevenRows = true;

			_places = new List<Place> ();
			_favoritePlaces = new List<Place>();
			
			_selectorElement = new WhatsHotViewModeSelectorElement (this);
			
			_places.Add (new Place ("Wonder Bar", Location.BostonMA, LocationType.Bar));
			_places.Add (new Place ("Rumor", Location.BostonMA, LocationType.NightClub));
			_places.Add (new Place ("Rise", Location.BostonMA, LocationType.NightClub));
			_places.Add (new Place ("Middlesex", Location.BostonMA, LocationType.NightClub));
			_places.Add (new Place ("Phoenix Landing", Location.BostonMA, LocationType.Bar));
			_places.Add (new Place ("Felt", Location.BostonMA, LocationType.NightClub));
			_places.Add (new Place ("Venu", Location.BostonMA, LocationType.NightClub));
			_places.Add (new Place ("Cure", Location.BostonMA, LocationType.NightClub));
			_places.Add (new Place ("Guilt", Location.BostonMA, LocationType.NightClub));

			_favoritePlaces.Add (new Place ("Middlesex", Location.BostonMA, LocationType.NightClub));
			_favoritePlaces.Add (new Place ("Felt", Location.BostonMA, LocationType.NightClub));
			_favoritePlaces.Add (new Place ("Venu", Location.BostonMA, LocationType.NightClub));

			Section viewModeSelectorSection = new Section ();
			
			viewModeSelectorSection.Add (_selectorElement as Element);
			
			Root.Add (viewModeSelectorSection);
			
			LoadBrowseView ();

			//This is how I will control the space between sections...
			this.TableView.SectionFooterHeight = 2;
			this.TableView.SectionHeaderHeight = 2;
		}
		
		public void LoadView(Segment segment)
		{
			switch(segment)
			{
			case Segment.Browse:
				LoadBrowseView();
				break;
			case Segment.Favorites:
				LoadFavoritesView();
				break;
			default:
				break;
			}
		}
		
		private void LoadBrowseView ()
		{
			Root.RemoveAt (1);
			
			Section contentSection = new Section ();
			
			List<Element> contentElements = new List<Element> ();
			
			foreach (Place place in _places) {
				contentElements.Add (new PlaceElement (place));
			}
			
			contentSection.AddAll (contentElements as IEnumerable<Element>);
			
			Root.Add (contentSection);			
		}

		private void LoadFavoritesView ()
		{
			Root.RemoveAt (1);
			
			Section contentSection = new Section ();
			
			List<Element> contentElements = new List<Element> ();

			foreach (Place place in _favoritePlaces) {
				contentElements.Add (new PlaceElement (place));
			}
			
			contentSection.AddAll (contentElements as IEnumerable<Element>);
			
			Root.Add (contentSection);			
		}
	}
}
